package com.example.a28796.beautiful.zhangyuqiadapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.a28796.beautiful.R;
import com.example.a28796.beautiful.zhangyuqibean.BeautyPagerBean;

import org.xutils.x;

import java.util.List;

/**
 * Created by admin on 2016/8/30.
 */
public class BeautyRecyAdapter extends RecyclerView.Adapter <BeautyRecyAdapter.BeautyRecyHolder>{
    private Context mContext;
    private List<BeautyPagerBean.ObjBean.AdsBean> mData;

    public BeautyRecyAdapter(Context mContext, List<BeautyPagerBean.ObjBean.AdsBean> mData) {
        this.mContext = mContext;
        this.mData = mData;
    }

    @Override
    public BeautyRecyAdapter.BeautyRecyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View  view = LayoutInflater.from(mContext).inflate(R.layout.item_beauty_recycle,null);
        BeautyRecyHolder holder = new BeautyRecyHolder(view);

        return holder;
    }

    @Override
    public void onBindViewHolder(BeautyRecyAdapter.BeautyRecyHolder holder, int position) {
        BeautyPagerBean.ObjBean.AdsBean adsBean = mData.get(position);
        holder.mTextViewTitle1.setText(adsBean.getTitle());
        holder.mTextViewTitle2.setText(adsBean.getSummary());
        holder.mImageView.setScaleType(ImageView.ScaleType.FIT_XY);
        x.image().bind(holder.mImageView,adsBean.getCover().getUrl());
    }

    @Override
    public int getItemCount() {
        return mData == null?0:mData.size();
    }

    public class BeautyRecyHolder extends RecyclerView.ViewHolder{
        private TextView mTextViewTitle1,mTextViewTitle2;
        private ImageView mImageView;
        public BeautyRecyHolder(View itemView) {
            super(itemView);
            mTextViewTitle1 = (TextView) itemView.findViewById(R.id.tv_recycle_title1);
            mTextViewTitle2 = (TextView) itemView.findViewById(R.id.tv_recycle_title2);
            mImageView = (ImageView) itemView.findViewById(R.id.iv_recycle_show);
        }
    }
}
